package com.hao.DaoImpl;

import com.hao.Dao.orderDao;
import com.hao.entity.order;
import com.hao.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/3.
 */
public class orderImpl  implements orderDao {
    @Override
    public List<order> find(int id) {
        List<order> list=new ArrayList<order>();
        String sql="SELECT *FROM  rh_order WHERE id like ? ";

        Connection conn=null;
        PreparedStatement state=null;
        ResultSet rs=null;
        try {
            conn= BaseDao.getConnection();
            state=conn.prepareStatement(sql);
            state.setString(1,"%"+id+"%");
            rs=state.executeQuery();
            while(rs.next()){
               order oo=new order();
               oo.setOrderid(rs.getInt("orderid"));
               oo.setSid(rs.getInt("sid"));
               oo.setAddtime(rs.getInt("addtime"));
               oo.setProid(rs.getInt("proid"));
                oo.setCityid(rs.getInt("cityid"));
                oo.setXid(rs.getInt("xid"));
                oo.setAddress(rs.getString("address"));
                oo.setIs_pay(rs.getString("is_pay"));
                oo.setUid(rs.getInt("uid"));
                oo.setSaleid(rs.getInt("saleid"));
                oo.setAppointment(rs.getString("appointment"));
                oo.setSpid(rs.getInt("spid"));
                oo.setPid(rs.getInt("pid"));
            list.add(oo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        finally{
            BaseDao.closeConnection(conn, state, rs);
        }
        return list;
    }

    @Override
    public int dele(int id) {
        String Sql="";
        Object[] ob={
                id
        };
        return BaseDao.Update(Sql,ob);
    }

    @Override
    public int dele(order add) {

        String Sql="";
        Object[] ob={

                add.getSid(),
                add.getAddtime(),
                add.getProid(),
                add.getCityid(),
                add.getXid(),
                add.getAddress(),
                add.getIs_pay(),
                add.getUid(),

                add.getSaleid(),
                add.getAppointment(),
                add.getSpid(),
                add.getPid(),
        };
        return BaseDao.Update(Sql,ob);
    }
}
